package com.yohann.designPattern.state;

import java.util.Random;

/**
 * <p>
 * 可以抽奖
 * </p>
 *
 * @author Yohann
 * @since 2021/2/13 17:24
 */
public class CanRaffle implements State {
    private RaffleActivity activity;

    public CanRaffle(RaffleActivity activity) {
        this.activity = activity;
    }

    @Override
    public void deductMoney() {
        System.out.println("你已扣取积分");
    }

    @Override
    public boolean raffle() {
        System.out.println("正在抽奖");
        Random random = new Random();
        int i = random.nextInt(5);
        if (i == 0) {
            activity.setState(activity.getDispense());
            return true;
        } else {
            System.out.println("很遗憾，您没有中奖！");
            activity.setState(activity.getNoRaffle());
            return false;
        }
    }

    @Override
    public void dispensePrize() {
        System.out.println("很遗憾，您没有中奖！");
    }
}